问个菜鸟问题->怎么对一维整形指针数组进行排序

来源:百度知道 编辑:UC知道 时间:2024/05/27 04:03:11
怎么对一维整形指针数组进行排序?
现在我定义了int *GetCoutRow = new int[];
for(int i = 0;i<PropertyCout;i++)
{
row = GetRowCoutListCtrlByPropertyList(PropertyList.GetAt(i));
GetCoutRow[i]= row;
}
并对数组赋了值。但我想求出这个指针的最大值。。。
希望虾哥们写出程序,谢谢了。
我知道有个排序是STL:sort但我不会用。
gexizhi_1989你那个n是怎么得到的?

如果我现在需要从大到小排序怎么排呢

#include<stdio.h>
void Sort(int *pArray,int iCount)
{
int i, j;
for(i = 0; i < iCount; i++)
{
for(j = 0; j < iCount-i-1; j++)
{
int iTmp;
if(*(pArray+j) < *(pArray+j+1))
{
iTmp = *(pArray+j);
*(pArray+j) = *(pArray+j+1);
*(pArray+j+1) = iTmp;
}
}
}
}

int main()
{
int a[5] = {1, 5, 7, 3, 2};
Sort(a,5);
return 0;
}

是用C++的有序容器就可以了

type
a:array [1..100] of 1..9;

简单的方法就是利用循环比较出最大值;

int nMax = GetCoutRow[0];//先假设第一个数为最大值
for(i=1;i<PropertyCout;i++) //循环,从第二个数据开始与最大值比较
{
if(nMax<GetCoutRow[i])
nMax = GetCoutRow[i]; //哪个数大于最大值,那么它就是新的最大值
}
//循环结束,nMax现在就是这个数组中的最大值了

求最大值不用排序。
看你的程序可以这样
#include <algorithm>

int _tmain(int argc, _TCHAR* argv[])
{
int a[10] = {0, 1, 4, 4,8, 2, 10, 22, 26, 333};
std::sort